package com.github.edu.manager.fwdl.controller;

import com.github.admin.edu.assembly.common.entity.JsonArray;
import com.github.admin.edu.assembly.page.entity.Pager;
import com.github.edu.client.common.annotation.*;
import com.github.edu.client.common.controller.BaseController;
import com.github.edu.manager.fwdl.service.WlflService;
import com.github.edu.manager.fwdl.service.WlkService;
import com.github.edu.repair.api.entity.TBxFwfl;
import com.github.edu.repair.api.entity.TBxWlk;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * Create by IntelliJ IDEA
 * 用户：王建
 * 日期：2018-8-21
 */
@Controller
@RequestMapping("/uc/wlk")
public class WlkManagerController extends BaseController<TBxWlk,Integer> {

    @Autowired
    private WlkService service;
    @Autowired
    private WlflService wlflService;

    @ModelAttribute
    public void getAllWlfl(ModelMap map){
        map.put("listWlfl",wlflService.getAll());
    }

    @QueryAll
    public String index(ModelMap modelMap, TBxWlk sysOauth, Pager pager) {
        if(null==pager){
            pager=new Pager();
        }
        pager.setDirection("ASC");
        String[] strs={"id"};
        pager.setOrder(strs);
        JsonArray<TBxWlk> jsonArray=service.getAllByPage(sysOauth,pager);
        return super.index(modelMap,sysOauth,jsonArray,"wlk","物料管理",
                "编码:id","物料名称:name","所属大类:clflmc",
                "维修方式:wxfs","单位:dw","材料费:clf","工时费:gsf");
    }

    @New
    public String add(ModelMap modelMap, TBxWlk sysOauth, HttpServletRequest request) {
        return super.newIndex(modelMap,sysOauth,"wlk","保存物料信息");
    }

    @Save
    public String saveOrUpdate(ModelMap modelMap, TBxWlk sysOauth, HttpServletRequest request) {
        sysOauth=service.saveOrUpdate(sysOauth);
        return super.saveObject(modelMap,sysOauth,"保存成功！","wlk","保存物料信息");
    }

    @Open
    public String openEntity(ModelMap modelMap,@PathVariable("id") Integer id) {
        TBxWlk application=service.getEntity(id);
        return super.openEntity(modelMap,application,"wlk","查看详情");
    }
    @Edit
    public String edit(ModelMap modelMap,@PathVariable("id") Integer s) {
        TBxWlk application=service.getEntity(s);
        return super.newIndex(modelMap,application,"wlk","修改物料信息");
    }

    @Delete
    public String delete( String ids) {
        return service.delete(ids);
    }
}
